extends Object
var parser = "/Users/qiulei/.pyenv/shims/luaparser" #ProjectSettings.globalize_path("res://lua/bin/luaparser")
var Opcode = preload("res://lua/OpcodeJs.gd")
var FileMgr = preload("res://command/FileManager.gd")
var environment=""
var shell=""
func _init():
	var result = []
	OS.execute("echo",["$SHELL"],true,result,true)
	shell=result[0].strip_edges(true,true)
	var paths="/etc/paths"
	var file =File.new()
	if file.file_exists(paths):
		file.open(paths, File.READ)
		var spath = file.get_line()
		while(spath):
			environment="%sexport PATH=%s:$PATH;" % [environment,spath]
			spath = file.get_line()
	file.close()
	
func exe_shell_script(script):
	var result =[]
	var script_temp = "\"'%s%s'\"" % [environment,script]
	print(script_temp)
	OS.execute(shell,["-c",script_temp],true,result,true)
	return result[0]

func getFileAST(file):
	var result = exe_shell_script(parser+" " + file)
	return result
	
func luaASTToLua(ast_json,filePath):
	#print(ast_json)
	var ast = JSON.parse(ast_json).result
	var Op=Opcode.new(ast,filePath)
	#print(Op.jscode)
	return Op.jscode
#	var chunk = ast["Chunk"]
#	var code = ""
#	if chunk and chunk["body"]:
#		var body = chunk["body"]
#		code = Op.luaBody(body)
#	#print("result\n")
	
	
func luaASTToJs():
	 pass
		
